/**
 * Created by Administrator on 2016/7/29.
 */
window.onload = function(){
    var out = document.querySelector('.right-1');
    var age = document.querySelector('.right-2');
    var one = document.querySelector('.right-3');
    out.style.backgroundColor = '#fa4862';
    out.addEventListener('mouseover',function(){
        out.style.backgroundColor = '#fa4862';
        age.style.backgroundColor = '#3a3a3a';
        one.style.backgroundColor = '#3a3a3a';
    })
    age.addEventListener('mouseover',function(){
        age.style.backgroundColor = '#fa4862';
        out.style.backgroundColor = '#3a3a3a';
        one.style.backgroundColor = '#3a3a3a';
    })
    one.addEventListener('mouseover',function(){
        one.style.backgroundColor = '#fa4862';
        age.style.backgroundColor = '#3a3a3a';
        out.style.backgroundColor = '#3a3a3a';
    })

    var rob1 = document.querySelector('.rob-1');
    var rob2 = document.querySelector('.rob-2');
    var rob3 = document.querySelector('.rob-3');
    var rob4 = document.querySelector('.rob-4');
    rob1.style.color = '#fa4862';
    rob1.addEventListener('mouseover',function(){
        rob1.style.color = '#fa4862';
        rob2.style.color = '#3a3a3a';
        rob3.style.color = '#3a3a3a';
        rob4.style.color = '#3a3a3a';
    })
    rob2.addEventListener('mouseover',function(){
        rob2.style.color = '#fa4862';
        rob1.style.color = '#3a3a3a';
        rob3.style.color = '#3a3a3a';
        rob4.style.color = '#3a3a3a';
    })
    rob3.addEventListener('mouseover',function(){
        rob3.style.color = '#fa4862';
        rob2.style.color = '#3a3a3a';
        rob1.style.color = '#3a3a3a';
        rob4.style.color = '#3a3a3a';
    })
    rob4.addEventListener('mouseover',function(){
        rob4.style.color = '#fa4862';
        rob2.style.color = '#3a3a3a';
        rob3.style.color = '#3a3a3a';
        rob1.style.color = '#3a3a3a';
    })

    var target_time = new Date('2016-08-02 17:50:00'.replace(/-/g,'/')).getTime();
    var now_time = new Date().getTime();
    var t = Math.floor((target_time - now_time) / 1000);
    var MIN = 60;
    var HOUR = MIN * 60;
    var DAY = HOUR * 24;
    function num(n) {
        var str = '0' + (n > 0 ? n : 0);
        return str.substr(-2);
    };
    function timer(){
        var days = Math.floor(t / DAY);
        var hours = Math.floor(t % DAY / HOUR);
        var minutes = Math.floor(t % HOUR / MIN);
        var seconds = Math.floor(t % MIN);

        if(t < 60){
            //小于60秒的
            var content = '刚刚发布';
        }else if(days <= 1){
            //如果是今天的就只显示小时，分钟和秒
            var content = num(hours) + "小时" + num(minutes) + "分后结束";

        }else{
            //如果不符合上面两个，就显示所有的
            var content =  num(hours) + "小时" + num(minutes) + "分后结束" ;
        }
        document.getElementById("timer1").innerHTML = content;
        document.getElementById("timer2").innerHTML = content;
        document.getElementById("timer3").innerHTML = content;
        document.getElementById("timer4").innerHTML = content;
        document.getElementById("timer5").innerHTML = content;
        document.getElementById("timer6").innerHTML = content;
        document.getElementById("timer7").innerHTML = content;
        document.getElementById("timer8").innerHTML = content;
        document.getElementById("timer9").innerHTML = content;
        document.getElementById("timer10").innerHTML = content;
        document.getElementById("timer11").innerHTML = content;
        document.getElementById("timer12").innerHTML = content;
        document.getElementById("timer13").innerHTML = content;
        document.getElementById("timer14").innerHTML = content;
        document.getElementById("timer15").innerHTML = content;
        document.getElementById("timer16").innerHTML = content;
        document.getElementById("timer17").innerHTML = content;
        document.getElementById("timer18").innerHTML = content;
        document.getElementById("timer19").innerHTML = content;
        document.getElementById("timer20").innerHTML = content;
    };
    function m() {
        timer();
        setTimeout(function() {
            t -= 1;
            timer();
            if (t > 0) {
                setTimeout(arguments.callee, 1000);
            }
        }, 1000);
    };
    m();


}
